package com.briup.day08;

import java.util.StringJoiner;

public class Homework {
    public static void main(String[] args) {
        Car car = new Car("五菱", "白色", 5.99);
//        car.color = "黑色";
        car.setColor("黑色");
        car.turn("左");
        car.show();
        Car car2 = new Car("华为", "红色", 49.99);
        car2.turn("右");
        car2.show();
    }
}

class Car {
    // 品牌
    String brand;
    // 颜色
    private String color;
    // 价格
    double price;

    public Car() {
    }

    /**
     * 在类内部给外部提供的合法访问和修改属性的途径
     */
    public void setColor(String color) {
        System.out.printf("用户向将%s的汽车颜色改为:%s%n", this, color);
        // 修改颜色
        this.color = color;
    }

    public Car(String brand, String color, double price) {
        this.brand = brand;
        this.color = color;
        this.price = price;
    }

    // 行为有：前进、后退、转弯和输出对象属性
    public void go() {
        System.out.printf("品牌为%s的汽车正在前进%n", brand);
    }

    public void back() {
        System.out.printf("倒车请注意！！！品牌为%s的汽车正在后退%n", brand);
    }

    /**
     * 小汽车进行转弯，转向由实际调用时传入
     *
     * @param veer 转向
     */
    public void turn(String veer) {
        System.out.printf("品牌为:%s的小汽车正在向%s转弯%n", brand, veer);
    }

    public void show() {
        StringJoiner s = new StringJoiner("；\n", "小汽车的详细信息如下：\n", "")
                .add("\t品牌:" + brand)
                .add("\t颜色:" + color)
                .add("\t价格:" + price + "万");
        System.out.println(s);
    }
}
